﻿using BLL;
using IBLL;
using Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Net.Http.Headers;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using user_defined_Panl;
using 考试管理系统;

namespace WindowsFormsApp1
{
    
    public partial class FrQuestionBankManage : Form
    {

        IFrQuestionBankManage_IBLL frQuestion=new FrQuestionBankManage_BLL();
        public FrQuestionBankManage()
        {
            InitializeComponent();

            Y();
        }
        public void Y()
        {
            int index = 1;
            SqlDataReader sqlData = frQuestion.Query();
            if (sqlData != null)
            {
                while (sqlData.Read())
                {
              
                    flowLayoutPanel1.Controls.Add(new FlowLayoutPanel_2(new MultipleChoice()
                    {
                        MCID = sqlData["SCID"].ToString(),
                        Topic = sqlData["Topic"].ToString(),
                        Answer = sqlData["Answer"].ToString(),
                        A = sqlData["A"].ToString(),
                        B = sqlData["B"].ToString(),
                        C = sqlData["C"].ToString(),
                        D = sqlData["D"].ToString(),
                        Score = sqlData["Score"].ToString()
                    }, index.ToString(), true, false));
                    index++;
                }
                 index = 1;
                if (sqlData.NextResult())
                {
                    while (sqlData.Read())
                    {
                        flowLayoutPanel2.Controls.Add(new FlowLayoutPanel_2(new MultipleChoice()
                        {
                            MCID = sqlData["MCID"].ToString(),
                            Topic = sqlData["Topic"].ToString(),
                            Answer = sqlData["Answer"].ToString(),
                            A = sqlData["A"].ToString(),
                            B = sqlData["B"].ToString(),
                            C = sqlData["C"].ToString(),
                            D = sqlData["D"].ToString(),
                            Score = sqlData["Score"].ToString()
                        }, index.ToString()));
                        index++;
                    }
                }
                index = 1;
                if (sqlData.NextResult())
                {
                    while (sqlData.Read())
                    {
                        flowLayoutPanel3.Controls.Add(new FlowLayoutPanel_3(new TrueOrFalseQuestions()
                        {
                            SPID = sqlData["SPID"].ToString(),
                            Topic = sqlData["Topic"].ToString(),
                            Answer = sqlData["Answer"].ToString(),
                            Score = sqlData["Score"].ToString()
                        }, index.ToString()));
                        index++;
                    }
                }
                index = 1;
                if (sqlData.NextResult())
                {
                    while (sqlData.Read())
                    {
                        flowLayoutPanel4.Controls.Add(new FlowLayoutPanel_4(new Completion()
                        {
                            CPID = sqlData["CPID"].ToString(),
                            Topic = sqlData["Topic"].ToString(),
                            Answer = sqlData["Answer"].ToString(),
                            Score = sqlData["Score"].ToString(),
                            ScoringPoint = sqlData["ScoringPoint"].ToString()
                        }, index.ToString()));
                        index++;
                    }
                }
                sqlData.Close();
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {

            Form1.flowLayoutPanel1 = flowLayoutPanel1;
            Form1.path = "添加单选题";
            Form1.max = 7;
       
            Form1 form = new Form1();
            form.ShowDialog();
          
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Form1.flowLayoutPanel1 = flowLayoutPanel2;
            Form1.max = 7;
            Form1 form = new Form1();
            Form1.path = "添加多选题";
            form.ShowDialog();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Form1.flowLayoutPanel1 = flowLayoutPanel3;
            Form1.max = 3;
            Form1 form = new Form1();
            Form1.path = "添加判断题";
            form.ShowDialog();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            Form1.flowLayoutPanel1 = flowLayoutPanel4;
            Form1.max = 4;
            Form1 form = new Form1();
            Form1.path = "添加填空题";
            form.ShowDialog();
        }
        public void Alters()
        {
            int t = 0;
            foreach (ContainerControl item in flowLayoutPanel1.Controls)
            {
                if ((item.Controls[0] as CheckBox).Checked == true)
                {
                    t++;
                }
                if (t > 1)
                {
                    break;
                }
            }
            if (t < 1 || t > 1)
            {
                MessageBox.Show("修改失败");
                return;
            }
        }

      
    }
}
